
#region Using Statements
using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

using Elephant.Utility;
using Elephant.Utility.Components;

using Elephant.Framework;
using Elephant.Framework.Services;

namespace UsingMaterials
{
    public class GameWindow : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;

        IContentService content;
        ISceneService scene;

        public GameWindow()
        {
            GameHelper.Game = this;

            graphics = new GraphicsDeviceManager(this);
            graphics.PreferMultiSampling = true;

            this.IsMouseVisible = true;
            this.Window.Title = String.Format("Elephant Samples: Using Materials");

            // installing the major services
            Components.Add(new SceneComponent(this));
            Components.Add(new ContentProvider(this));

            // getting a reference to the services (could have just kept the references as we installed them)
            scene = Services.GetService(typeof(ISceneService)) as ISceneService;
            content = Services.GetService(typeof(IContentService)) as IContentService;
        }

        protected override void Initialize()
        {
            Entity camera = scene.Factory.Create<Entity>("A Camera", new LookAtCamera());
            camera.Find<Transform>().Position = new Vector3(-10, -2, -10);
            camera.Find<Camera>().ClearColor = Color.CornflowerBlue;

            Entity sphere = scene.Factory.Create<Entity>("Sphere", new SphereRender());
            // uncomment to change the ambient color of the material
            //sphere.Find<LambertMaterial>().AmbientColor = Color.Red.ToVector4();

            base.Initialize();
        }

        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent) {
                content.Unload();
            }
        }
    }
}
